package com.ws.genercity.demo07;

import java.util.Comparator;
import java.util.TreeSet;

/**
 * @author 13353
 * 类型通配符下限配置
 */
public class Test08 {
    public static void main(String[] args) {
        //升序
        TreeSet<Cat> treeSet = new TreeSet<>(new Comparatorl2());
        //名字升序
        //TreeSet<Cat> treeSet = new TreeSet<>(new Comparatorl());
        // 下限通配符，范围小
        // TreeSet<Cat> treeSet = new TreeSet<>(new Comparatorl3());
        treeSet.add(new Cat("lisi ",18));
        treeSet.add(new Cat("王五 ",20));
        treeSet.add(new Cat("赵六 ",22));
        treeSet.add(new Cat("赵云 ",15));
        treeSet.add(new Cat("李白 ",43));
        for (Cat cat : treeSet) {
            System.out.println(cat);
        }
    }
}

/**
 * 比较animal 比较器
 */
class Comparatorl implements Comparator<Animal> {

    @Override
    public int compare(Animal o1, Animal o2) {
        return o1.name.compareTo(o2.name);
    }
}

//比较cat
class Comparatorl2 implements Comparator<Cat> {

    @Override
    public int compare(Cat o1, Cat o2) {
        return o1.age - o2.age;
    }
}

//比较cat
class Comparatorl3 implements Comparator<MiniCat> {

    @Override
    public int compare(MiniCat o1, MiniCat o2) {
        return o1.level - o2.level;
    }
}
